home *** CD-ROM | disk | FTP | other *** search
/ Hardcore Visual Basic 5.0 (2nd Edition) / Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso / Code / texecute.frm < prev    next >
Text File  |  1997-06-14  |  25KB  |  819 lines

  1. VERSION 5.00
  2. Begin VB.Form FTestExecute 
  3.    AutoRedraw      =   -1  'True
  4.    Caption         =   "Test Execute"
  5.    ClientHeight    =   3960
  6.    ClientLeft      =   1020
  7.    ClientTop       =   2655
  8.    ClientWidth     =   7050
  9.    BeginProperty Font 
  10.       Name            =   "MS Sans Serif"
  11.       Size            =   8.25
  12.       Charset         =   0
  13.       Weight          =   700
  14.       Underline       =   0   'False
  15.       Italic          =   0   'False
  16.       Strikethrough   =   0   'False
  17.    EndProperty
  18.    Icon            =   "texecute.frx":0000
  19.    LinkTopic       =   "Form1"
  20.    ScaleHeight     =   3960
  21.    ScaleWidth      =   7050
  22.    Begin VB.TextBox txtPipeIn 
  23.       Height          =   960
  24.       Left            =   132
  25.       MultiLine       =   -1  'True
  26.       ScrollBars      =   3  'Both
  27.       TabIndex        =   45
  28.       Top             =   4224
  29.       Width           =   6828
  30.    End
  31.    Begin VB.TextBox txtPipeOut 
  32.       Height          =   1040
  33.       Left            =   120
  34.       MultiLine       =   -1  'True
  35.       ScrollBars      =   3  'Both
  36.       TabIndex        =   44
  37.       Top             =   5472
  38.       Width           =   6828
  39.    End
  40.    Begin VB.Frame fmPlus 
  41.       Caption         =   "Extra Execute Options"
  42.       Height          =   1695
  43.       Left            =   4110
  44.       TabIndex        =   39
  45.       Top             =   45
  46.       Width           =   2790
  47.       Begin VB.TextBox txtLeft 
  48.          Height          =   330
  49.          Left            =   930
  50.          TabIndex        =   13
  51.          Text            =   "-1"
  52.          Top             =   870
  53.          Width           =   510
  54.       End
  55.       Begin VB.TextBox txtTop 
  56.          Height          =   330
  57.          Left            =   2175
  58.          TabIndex        =   14
  59.          Text            =   "-1"
  60.          Top             =   870
  61.          Width           =   510
  62.       End
  63.       Begin VB.TextBox txtDir 
  64.          Height          =   315
  65.          Left            =   105
  66.          TabIndex        =   12
  67.          Top             =   480
  68.          Width           =   2580
  69.       End
  70.       Begin VB.TextBox txtWidth 
  71.          Height          =   315
  72.          Left            =   924
  73.          TabIndex        =   15
  74.          Text            =   "-1"
  75.          Top             =   1275
  76.          Width           =   510
  77.       End
  78.       Begin VB.TextBox txtHeight 
  79.          Height          =   315
  80.          Left            =   2160
  81.          TabIndex        =   16
  82.          Text            =   "-1"
  83.          Top             =   1272
  84.          Width           =   510
  85.       End
  86.       Begin VB.Label lbl 
  87.          Caption         =   "Working directory:"
  88.          Height          =   270
  89.          Index           =   3
  90.          Left            =   150
  91.          TabIndex        =   26
  92.          Top             =   255
  93.          Width           =   1755
  94.       End
  95.       Begin VB.Label lbl 
  96.          Caption         =   "Left:"
  97.          Height          =   270
  98.          Index           =   9
  99.          Left            =   135
  100.          TabIndex        =   25
  101.          Top             =   915
  102.          Width           =   570
  103.       End
  104.       Begin VB.Label lbl 
  105.          Caption         =   "Top:"
  106.          Height          =   270
  107.          Index           =   10
  108.          Left            =   1485
  109.          TabIndex        =   23
  110.          Top             =   915
  111.          Width           =   570
  112.       End
  113.       Begin VB.Label lbl 
  114.          Caption         =   "Width:"
  115.          Height          =   270
  116.          Index           =   11
  117.          Left            =   135
  118.          TabIndex        =   24
  119.          Top             =   1305
  120.          Width           =   615
  121.       End
  122.       Begin VB.Label lbl 
  123.          Caption         =   "Height:"
  124.          Height          =   270
  125.          Index           =   12
  126.          Left            =   1485
  127.          TabIndex        =   40
  128.          Top             =   1305
  129.          Width           =   675
  130.       End
  131.    End
  132.    Begin VB.Frame fmChar 
  133.       Caption         =   "Character Mode Options"
  134.       Height          =   1995
  135.       Left            =   4110
  136.       TabIndex        =   33
  137.       Top             =   1800
  138.       Width           =   2790
  139.       Begin VB.CheckBox chkPipe 
  140.          Caption         =   "Use Pipes"
  141.          Height          =   195
  142.          Left            =   1485
  143.          MaskColor       =   &H00000000&
  144.          TabIndex        =   43
  145.          Top             =   1680
  146.          Width           =   1260
  147.       End
  148.       Begin VB.ComboBox cboFront 
  149.          Height          =   315
  150.          ItemData        =   "texecute.frx":0CFA
  151.          Left            =   105
  152.          List            =   "texecute.frx":0D31
  153.          Style           =   2  'Dropdown List
  154.          TabIndex        =   20
  155.          Top             =   1290
  156.          Width           =   1275
  157.       End
  158.       Begin VB.CheckBox chkFull 
  159.          Caption         =   "Full Screen"
  160.          Height          =   195
  161.          Left            =   120
  162.          MaskColor       =   &H00000000&
  163.          TabIndex        =   22
  164.          Top             =   1680
  165.          Width           =   1296
  166.       End
  167.       Begin VB.ComboBox cboBack 
  168.          Height          =   315
  169.          ItemData        =   "texecute.frx":0DBE
  170.          Left            =   1485
  171.          List            =   "texecute.frx":0DF5
  172.          Style           =   2  'Dropdown List
  173.          TabIndex        =   21
  174.          Top             =   1290
  175.          Width           =   1200
  176.       End
  177.       Begin VB.TextBox txtRow 
  178.          Height          =   360
  179.          Left            =   2175
  180.          TabIndex        =   19
  181.          Text            =   "-1"
  182.          Top             =   660
  183.          Width           =   510
  184.       End
  185.       Begin VB.TextBox txtCol 
  186.          Height          =   345
  187.          Left            =   930
  188.          TabIndex        =   18
  189.          Text            =   "-1"
  190.          Top             =   660
  191.          Width           =   510
  192.       End
  193.       Begin VB.TextBox txtTitle 
  194.          Height          =   315
  195.          Left            =   645
  196.          TabIndex        =   17
  197.          Text            =   "Test Execute"
  198.          Top             =   240
  199.          Width           =   2040
  200.       End
  201.       Begin VB.Label lbl 
  202.          Caption         =   "Back Color:"
  203.          Height          =   225
  204.          Index           =   5
  205.          Left            =   1485
  206.          TabIndex        =   38
  207.          Top             =   1050
  208.          Width           =   1260
  209.          WordWrap        =   -1  'True
  210.       End
  211.       Begin VB.Label lbl 
  212.          Caption         =   "Front Color:"
  213.          Height          =   210
  214.          Index           =   15
  215.          Left            =   105
  216.          TabIndex        =   37
  217.          Top             =   1050
  218.          Width           =   1140
  219.          WordWrap        =   -1  'True
  220.       End
  221.       Begin VB.Label lbl 
  222.          Caption         =   "Rows:"
  223.          Height          =   270
  224.          Index           =   14
  225.          Left            =   1560
  226.          TabIndex        =   36
  227.          Top             =   705
  228.          Width           =   570
  229.       End
  230.       Begin VB.Label lbl 
  231.          Caption         =   "Columns:"
  232.          Height          =   270
  233.          Index           =   13
  234.          Left            =   120
  235.          TabIndex        =   35
  236.          Top             =   705
  237.          Width           =   795
  238.       End
  239.       Begin VB.Label lbl 
  240.          Caption         =   "Title:"
  241.          Height          =   270
  242.          Index           =   4
  243.          Left            =   150
  244.          TabIndex        =   34
  245.          Top             =   285
  246.          Width           =   600
  247.       End
  248.    End
  249.    Begin VB.Timer tmrWait 
  250.       Enabled         =   0   'False
  251.       Interval        =   200
  252.       Left            =   6732
  253.       Top             =   4032
  254.    End
  255.    Begin VB.TextBox txtArgs 
  256.       Height          =   315
  257.       Left            =   1755
  258.       TabIndex        =   2
  259.       Top             =   960
  260.       Width           =   2235
  261.    End
  262.    Begin VB.TextBox txtProgram 
  263.       Height          =   315
  264.       Left            =   132
  265.       TabIndex        =   1
  266.       Top             =   960
  267.       Width           =   1575
  268.    End
  269.    Begin VB.Frame frame 
  270.       Caption         =   "Display Options"
  271.       Height          =   1695
  272.       Index           =   1
  273.       Left            =   132
  274.       TabIndex        =   28
  275.       Top             =   1395
  276.       Width           =   1680
  277.       Begin VB.CheckBox chkMax 
  278.          Caption         =   "Maximized"
  279.          Height          =   255
  280.          Left            =   120
  281.          MaskColor       =   &H00000000&
  282.          TabIndex        =   7
  283.          Top             =   1320
  284.          Width           =   1380
  285.       End
  286.       Begin VB.CheckBox chkMin 
  287.          Caption         =   "Minimized"
  288.          Height          =   255
  289.          Left            =   120
  290.          MaskColor       =   &H00000000&
  291.          TabIndex        =   6
  292.          Top             =   990
  293.          Width           =   1485
  294.       End
  295.       Begin VB.CheckBox chkFocus 
  296.          Caption         =   "Has Focus"
  297.          Height          =   255
  298.          Left            =   120
  299.          MaskColor       =   &H00000000&
  300.          TabIndex        =   5
  301.          Top             =   660
  302.          Value           =   1  'Checked
  303.          Width           =   1500
  304.       End
  305.       Begin VB.CheckBox chkHidden 
  306.          Caption         =   "Hidden"
  307.          Height          =   255
  308.          Left            =   120
  309.          MaskColor       =   &H00000000&
  310.          TabIndex        =   4
  311.          Top             =   330
  312.          Width           =   1515
  313.       End
  314.    End
  315.    Begin VB.CommandButton cmdRun 
  316.       Caption         =   "Run"
  317.       Default         =   -1  'True
  318.       Height          =   375
  319.       Left            =   132
  320.       MaskColor       =   &H00000000&
  321.       TabIndex        =   3
  322.       Top             =   3204
  323.       Width           =   1215
  324.    End
  325.    Begin VB.Frame frame 
  326.       Caption         =   "Execute Options"
  327.       Height          =   1710
  328.       Index           =   0
  329.       Left            =   1875
  330.       TabIndex        =   27
  331.       Top             =   1395
  332.       Width           =   2115
  333.       Begin VB.CheckBox chkDead 
  334.          Caption         =   "Dead"
  335.          Enabled         =   0   'False
  336.          Height          =   255
  337.          Left            =   1068
  338.          MaskColor       =   &H00000000&
  339.          TabIndex        =   42
  340.          Top             =   324
  341.          Width           =   888
  342.       End
  343.       Begin VB.OptionButton optRun 
  344.          Caption         =   "VBShellExecute"
  345.          Height          =   270
  346.          Index           =   2
  347.          Left            =   120
  348.          MaskColor       =   &H00000000&
  349.          TabIndex        =   11
  350.          Top             =   1320
  351.          Width           =   1725
  352.       End
  353.       Begin VB.OptionButton optRun 
  354.          Caption         =   "Executive"
  355.          Height          =   270
  356.          Index           =   1
  357.          Left            =   120
  358.          MaskColor       =   &H00000000&
  359.          TabIndex        =   10
  360.          Top             =   990
  361.          Value           =   -1  'True
  362.          Width           =   1695
  363.       End
  364.       Begin VB.OptionButton optRun 
  365.          Caption         =   "Shell"
  366.          Height          =   270
  367.          Index           =   0
  368.          Left            =   120
  369.          MaskColor       =   &H00000000&
  370.          TabIndex        =   9
  371.          Top             =   675
  372.          Width           =   1515
  373.       End
  374.       Begin VB.CheckBox chkWait 
  375.          Caption         =   "Wait"
  376.          Height          =   255
  377.          Left            =   120
  378.          MaskColor       =   &H00000000&
  379.          TabIndex        =   8
  380.          Top             =   330
  381.          Width           =   1095
  382.       End
  383.    End
  384.    Begin VB.TextBox txtCmd 
  385.       Height          =   300
  386.       Left            =   132
  387.       TabIndex        =   0
  388.       Top             =   375
  389.       Width           =   3900
  390.    End
  391.    Begin VB.Label lbl 
  392.       Caption         =   "Piped output text:"
  393.       Height          =   216
  394.       Index           =   7
  395.       Left            =   144
  396.       TabIndex        =   47
  397.       Top             =   5232
  398.       Width           =   1596
  399.    End
  400.    Begin VB.Label lbl 
  401.       Caption         =   "Piped input text:"
  402.       Height          =   252
  403.       Index           =   6
  404.       Left            =   132
  405.       TabIndex        =   46
  406.       Top             =   3936
  407.       Width           =   1572
  408.    End
  409.    Begin VB.Label lblExeType 
  410.       Height          =   240
  411.       Left            =   1692
  412.       TabIndex        =   41
  413.       Top             =   72
  414.       Width           =   2436
  415.    End
  416.    Begin VB.Label lbl 
  417.       Caption         =   "Arguments:"
  418.       Height          =   255
  419.       Index           =   2
  420.       Left            =   1785
  421.       TabIndex        =   29
  422.       Top             =   720
  423.       Width           =   1575
  424.    End
  425.    Begin VB.Label lbl 
  426.       Caption         =   "Program:"
  427.       Height          =   255
  428.       Index           =   1
  429.       Left            =   132
  430.       TabIndex        =   30
  431.       Top             =   720
  432.       Width           =   1095
  433.    End
  434.    Begin VB.Label lblStatus 
  435.       Height          =   636
  436.       Left            =   1632
  437.       TabIndex        =   32
  438.       Top             =   3168
  439.       Width           =   2340
  440.    End
  441.    Begin VB.Label lbl 
  442.       Caption         =   "Command line:"
  443.       Height          =   255
  444.       Index           =   0
  445.       Left            =   75
  446.       TabIndex        =   31
  447.       Top             =   75
  448.       Width           =   1575
  449.    End
  450. End
  451. Attribute VB_Name = "FTestExecute"
  452. Attribute VB_GlobalNameSpace = False
  453. Attribute VB_Creatable = False
  454. Attribute VB_PredeclaredId = True
  455. Attribute VB_Exposed = False
  456. Option Explicit
  457.  
  458. Private idProg As Long
  459. Private fCmdFocus As Boolean
  460. Private sRunMode As String, sProgram As String, sArgs As String
  461. Private dx As Long, dxBorder As Long, dy As Long, dyBorder As Long
  462.  
  463. Private Sub Form_Load()
  464.     txtProgram.Text = "Notepad"
  465.     dx = Width
  466.     dy = Height
  467.     dxBorder = Width - ScaleWidth
  468.     dyBorder = Height - ScaleHeight
  469.     optRun_Click 1
  470.     'optRun(1).Value = True
  471.     cboFront.ListIndex = 0
  472.     cboBack.ListIndex = 0
  473.     
  474. #Const fTesting = 0
  475. #If fTesting Then
  476.     Dim exec As New CExecutive
  477.     exec.Run "Notepad"
  478.  
  479.     Dim idProg As Long, iExit As Long
  480.     idProg = Shell("mktyplib shelllnk.odl", vbHide)
  481.     iExit = WaitOnProgram(idProg)
  482.     If iExit Then MsgBox "Compile failed"
  483.  
  484.     With exec
  485.         .WaitMode = ewmWaitIdle
  486.         .Show = vbHide
  487.         .Run "mktyplib shelllnk.odl"
  488.         If .ExitCode Then MsgBox "Compile failed"
  489.     End With
  490.     With exec
  491.         ' Notepad half the screen size 20 percent in from left and top
  492.         .Left = Screen.Width / Screen.TwipsPerPixelX * 0.2
  493.         .Top = Screen.Height / Screen.TwipsPerPixelY * 0.2
  494.         .Width = Screen.Width / Screen.TwipsPerPixelX * 0.5
  495.         .Height = Screen.Height / Screen.TwipsPerPixelY * 0.5
  496.         .Show = vbNormalFocus
  497.         .InitDir = Left$(CurDir$, 3)
  498.         .WaitMode = ewmNoWait
  499.         .Run "Notepad colors.txt"
  500.         .Title = "The Meaning of Life"
  501.         .Left = Screen.Width / Screen.TwipsPerPixelX * 0.1
  502.         .Top = Screen.Height / Screen.TwipsPerPixelY * 0.1
  503.         ' Start a red on cyan command session 70 columns by 64 rows
  504.         .Columns = 70
  505.         .Rows = 64
  506.         .BackColor = qbGreen
  507.         .ForeColor = qbLightYellow
  508.         .Run "%COMSPEC% /k dir"
  509.     End With
  510.     Dim sUnsortedText As String, sSortedText As String
  511.     sUnsortedText = "5" & sCrLf & "3" & sCrLf & "2" & sCrLf & "7" & sCrLf
  512.     With exec
  513.         .PipedInText = sUnsortedText
  514.         .Show = vbHide
  515.         .WaitMode = ewmWaitDead
  516.         .Run "sort"
  517.         sSortedText = .PipedOutText
  518.     End With
  519. #End If
  520. End Sub
  521.  
  522. Private Sub Form_Unload(Cancel As Integer)
  523.     If chkWait = False And IsRunning(idProg) Then
  524.         MsgBox "Can't quit until program finishes or you turn off waiting"
  525.         Cancel = True
  526.     End If
  527. End Sub
  528.  
  529. Private Sub cmdRun_Click()
  530.     Dim ewmWait As EWaitMode, hPipeRead As Long, sError As String
  531.     ewmWait = -chkWait
  532.     If chkDead Then ewmWait = -ewmWait
  533.     cmdRun.SetFocus
  534.     txtPipeOut = sEmpty
  535.     Dim res As VbMsgBoxResult, ept As EProgramType
  536.     Const sMsg = "You could wait forever for a hidden Windows program!"
  537.     If txtProgram <> sEmpty Then
  538.         ept = ExeType(SearchForExe(txtProgram))
  539.         If chkHidden And ept <> eptMSDOS And ept <> eptWin32Console Then
  540.             If MsgBox(sMsg, vbOKCancel) = vbCancel Then Exit Sub
  541.         End If
  542.     End If
  543.     lblStatus.Caption = "Executing..."
  544.     lblStatus.Refresh
  545.     On Error GoTo RunFail
  546.     Select Case sRunMode
  547.     Case "Shell"
  548.         idProg = Shell(txtCmd.Text, GetDisplay)
  549.         If chkWait Then WaitOnProgram idProg, chkDead
  550.         If chkWait Then
  551.             lblStatus.Caption = sRunMode & " returned"
  552.         Else
  553.             lblStatus.Caption = sEmpty
  554.             tmrWait.Enabled = True
  555.         End If
  556.     Case "Executive"
  557.         Dim exec As New CExecutive, sChunk As String
  558.         With exec
  559.             .Show = GetDisplay
  560.             .WaitMode = ewmWait
  561.             If txtDir <> sEmpty Then .InitDir = txtDir
  562.             .Left = txtLeft
  563.             .Top = txtTop
  564.             .Width = txtWidth
  565.             .Height = txtHeight
  566.             .Title = txtTitle
  567.             .Columns = txtCol
  568.             .Rows = txtRow
  569.             .BackColor = cboFront.ListIndex - 1
  570.             .ForeColor = cboBack.ListIndex - 1
  571.             .FullScreen = (chkFull = vbChecked)
  572.             .PipedInText = txtPipeIn
  573.             .Run txtCmd.Text
  574.             If .WaitMode = ewmNoWait Then
  575.                 lblStatus.Caption = sEmpty
  576.                 Do
  577.                     Dim c As Long
  578.                     ' A real program would do work here
  579.                     DoWaitEvents 50
  580.                     lblStatus.Caption = "Working: " & c
  581.                     c = c + 1
  582.                 Loop Until .ReadPipeChunk And .Completed
  583.             End If
  584.             txtPipeOut = .PipedOutText
  585.         End With
  586.     Case "VBShellExecute"
  587.         Dim sSpec As String, sArgs As String, sProg As String
  588.         sArgs = txtArgs.Text
  589.         sProg = txtProgram.Text
  590.         If sProg = sEmpty Then
  591.             sSpec = sArgs
  592.         Else
  593.             If HasShell Then
  594.                 sSpec = sProg
  595.             Else
  596.                 sSpec = SearchForExe(sProg)
  597.             End If
  598.         End If
  599.         Call VBShellExecute(sSpec, sArgs, GetDisplay)
  600.     End Select
  601.     Exit Sub
  602. RunFail:
  603.     lblStatus.Caption = sRunMode & " failed: " & _
  604.                         Err.Description
  605.  
  606. End Sub
  607.  
  608. Private Sub chkWait_Click()
  609.     chkDead.Enabled = chkWait
  610.     chkDead.Value = vbUnchecked
  611.     Debug.Print chkWait
  612. End Sub
  613.  
  614. Private Sub chkFocus_Click()
  615.     If chkFocus.Value = vbUnchecked And chkMax.Value = vbChecked Then
  616.         chkMax.Value = vbUnchecked
  617.     End If
  618.     If chkFocus.Value = vbChecked Then chkHidden.Value = vbUnchecked
  619. End Sub
  620.  
  621. Private Sub chkHidden_Click()
  622.     If chkHidden.Value = vbChecked Then
  623.         chkFocus.Value = vbUnchecked
  624.         chkMin.Value = vbUnchecked
  625.         chkMax.Value = vbUnchecked
  626.     End If
  627.     'proc.Visible = (chkHidden.Value = 0)
  628. End Sub
  629.  
  630. Private Sub chkMax_Click()
  631.     If chkMax.Value = vbChecked Then
  632.         chkMin.Value = vbUnchecked
  633.         chkFocus.Value = vbChecked
  634.         chkHidden.Value = vbUnchecked
  635.     End If
  636. End Sub
  637.  
  638. Private Sub chkMin_Click()
  639.     If chkMin.Value = vbChecked Then
  640.         chkMax.Value = vbUnchecked
  641.         chkHidden.Value = vbUnchecked
  642.     End If
  643. End Sub
  644.  
  645. Private Sub chkPipe_Click()
  646.     Static ordLast(1 To 4) As Long
  647.     If chkPipe Then
  648.         Height = txtPipeOut.Top + txtPipeOut.Height + dyBorder + dxBorder
  649.         ordLast(1) = chkHidden
  650.         ordLast(2) = chkFocus
  651.         ordLast(3) = chkMin
  652.         ordLast(4) = chkMax
  653.         chkHidden = vbChecked
  654.     Else
  655.         Height = dy
  656.         chkHidden = ordLast(1)
  657.         chkFocus = ordLast(2)
  658.         chkMin = ordLast(3)
  659.         chkMax = ordLast(4)
  660.     End If
  661. End Sub
  662.  
  663. Private Sub optRun_Click(Index As Integer)
  664.     sRunMode = optRun(Index).Caption
  665.     Select Case sRunMode
  666.     Case "Shell"
  667.         chkWait.Enabled = True
  668.         Width = fmChar.Left + dxBorder
  669.         Height = fmChar.Top + fmChar.Height + dyBorder
  670.         chkWait_Click
  671.     Case "Executive"
  672.         chkWait.Enabled = True
  673.         Width = dx
  674.         Height = dy
  675.         chkPipe_Click
  676.         chkWait_Click
  677.     Case "VBShellExecute"
  678.         Width = fmChar.Left + dxBorder
  679.         Height = fmChar.Top + fmChar.Height + dyBorder
  680.         chkWait.Enabled = False
  681.         chkWait.Value = vbUnchecked
  682.         chkDead.Enabled = False
  683.         chkDead.Value = vbUnchecked
  684.     End Select
  685. End Sub
  686.  
  687. Private Sub tmrWait_Timer()
  688.     Static c As Long
  689.     If chkWait = False And IsRunning(idProg) Then
  690.         lblStatus.Caption = "Working: " & c
  691.         c = c + 1
  692.     Else
  693.         lblStatus.Caption = "Program returned"
  694.         tmrWait.Enabled = False
  695.         c = 0
  696.     End If
  697. End Sub
  698.  
  699. Private Sub txtCmd_Change()
  700.     If fCmdFocus Then sCmdLine = txtCmd.Text
  701.     txtProgram.Text = sProgram
  702.     txtArgs.Text = sArgs
  703. End Sub
  704.  
  705. Private Sub txtArgs_Change()
  706.     sArgs = txtArgs.Text
  707.     txtCmd.Text = sCmdLine
  708. End Sub
  709.  
  710. Private Sub txtPipeIn_GotFocus()
  711.     cmdRun.Default = False
  712. End Sub
  713.  
  714. Private Sub txtPipeIn_LostFocus()
  715.     cmdRun.Default = True
  716. End Sub
  717.  
  718. Private Sub txtProgram_Change()
  719.     sProgram = txtProgram.Text
  720.     txtCmd.Text = sCmdLine
  721. End Sub
  722.  
  723. Private Sub txtProgram_GotFocus()
  724. With txtProgram
  725.     .SelStart = 0
  726.     .SelLength = Len(.Text)
  727.     fCmdFocus = False
  728.     If .Text <> sEmpty Then lblExeType.Caption = ExeTypeStr(SearchForExe(.Text))
  729. End With
  730. End Sub
  731.  
  732. Private Sub txtCmd_GotFocus()
  733. With txtCmd
  734.     .SelStart = 0
  735.     .SelLength = Len(.Text)
  736.     fCmdFocus = True
  737.     If .Text <> sEmpty Then lblExeType.Caption = ExeTypeStr(SearchForExe(.Text))
  738. End With
  739. End Sub
  740.  
  741. Private Sub txtArgs_GotFocus()
  742. With txtArgs
  743.     .SelStart = 0
  744.     .SelLength = Len(.Text)
  745.     fCmdFocus = False
  746.     If .Text <> sEmpty Then
  747.         lblExeType.Caption = ExeTypeStr(SearchForExe(.Text))
  748.     End If
  749. End With
  750. End Sub
  751.  
  752. Private Sub InitControls()
  753.     txtProgram.Text = GetFileBase(Environ$("COMSPEC"))
  754.     txtArgs.Text = sEmpty
  755.     chkHidden.Value = vbUnchecked
  756.     chkFocus.Value = vbChecked
  757.     chkMin.Value = vbUnchecked
  758.     chkMax.Value = vbUnchecked
  759.     chkWait.Value = vbChecked
  760. End Sub
  761.  
  762. ' Convert Process properties to constants expected by Shell
  763. Private Function GetDisplay() As Long
  764.     If chkHidden.Value = vbChecked Then
  765.         GetDisplay = vbHide
  766.     ElseIf chkFocus.Value = vbChecked Then         ' (with focus)
  767.         If chkMin.Value = vbChecked Then
  768.             GetDisplay = vbMinimizedFocus
  769.         ElseIf chkMax.Value = vbChecked Then
  770.             GetDisplay = vbMaximizedFocus
  771.         Else
  772.             GetDisplay = vbNormalFocus
  773.         End If
  774.     Else                        ' Disabled (without focus)
  775.         If chkMin.Value = vbChecked Then
  776.             GetDisplay = vbNormalNoFocus
  777.         ElseIf chkMax.Value = vbChecked Then
  778.             ' No such thing as maximized without focus
  779.             GetDisplay = vbMaximizedFocus
  780.         Else
  781.             GetDisplay = vbNormalNoFocus
  782.         End If
  783.     End If
  784. End Function
  785.  
  786. Private Property Get sCmdLine() As String
  787.     If sProgram = sEmpty Then
  788.         sCmdLine = sArgs
  789.     ElseIf sArgs = sEmpty Then
  790.         sCmdLine = sProgram
  791.     Else
  792.         sCmdLine = sProgram & " " & sArgs
  793.     End If
  794. End Property
  795.  
  796. Private Property Let sCmdLine(sCmdLineA As String)
  797.     sCmdLineA = LTrim$(sCmdLineA)
  798.     Dim i As Integer, iT As Integer
  799.     ' Check for quoted program name
  800.     If Left$(sCmdLineA, 1) = """" Then
  801.         i = InStr(sCmdLineA, """")
  802.         If i Then i = i + 1
  803.     Else
  804.         ' Find first space or tab
  805.         i = InStr(sCmdLineA, " ")
  806.         iT = InStr(sCmdLineA, sTab)
  807.         If iT And i > iT Then i = iT
  808.     End If
  809.     If i = 0 Then
  810.         ' No tab or space, no argument
  811.         sProgram = sCmdLineA
  812.         sArgs = sEmpty
  813.     Else
  814.         ' Split out the parts
  815.         sProgram = Left$(sCmdLineA, i - 1)
  816.         sArgs = Mid$(sCmdLineA, i + 1)
  817.     End If
  818. End Property
  819.